import co
import runtime

fn car() {
    var a = vec_new<int>(0, 10)
    a = vec_new<int>(0, 403)
    a = vec_new<int>(0, 1201)
    a = vec_new<int>(0, 512)
    a = vec_new<int>(0, 700)

    var c = {1:2, 2:3, 3:4}

    a[0] = 1
    a[2] = 2
    a[4] = 4
    a[8] = 8
    a[16] = 16
    a[32] = 32
    a[128] = 128
    a[500] = 128

    var b = 'hello world nice'
    b = 'hello world nice'
    b = 'wwwwwwwwwwww'
    b = 'ccccccccccccc'
    b = 'bbbbbbbbbbbbbb'
    b = 'hello world nice'
    b = 'hello world nice'
}

fn foo(){
    int a = 1
    int b = 2
    bool c = true
    string d = 'hello world'
    d = 'done done'
    car()
    runtime.gc()

    co.sleep(100)
    print('share sub_co done\n')
}

fn main() {
    var bar = fn(){
        var i = 2
        for i > 0 {
            co.sleep(100)
            i -= 1
        }

        println('solo sub_co done', i)
    }


    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar())
    @async(bar(), co.SAME)
    @async(bar(), co.SAME)
    @async(bar(), co.SAME)
    @async(bar(), co.SAME)

    for int i=0; i < 100; i+=1 {
       @async(foo(), 0)
    }

    for int i=0; i < 100; i+=1 {
       @async(bar(), co.SAME)
    }

    for int i=0; i < 300; i+=1 {
       go bar()
    }

    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)

    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)

    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)
    @async(foo(), 0)

    // main for sleep
    for int i=0; i<25; i+=1 {
        co.sleep(10)
        if i > 20 {
            println('main_co sleep done', i)
        }
    }

    println('main_co done')
}